// JavaScript Document

var dDate = new Date();
var dCurMonth = dDate.getMonth();
var dCurDayOfMonth = dDate.getDate();
var dCurYear = dDate.getFullYear();
var objPrevElement = new Object();
 
function fToggleColor(myElement) {
	var toggleColor = "#ff0000";
	if (myElement.id == "calDateText") {
		if (myElement.color == toggleColor) {
			myElement.color = "";
		} else {
			myElement.color = toggleColor;
   		}
	} else if (myElement.id == "calCell") {
		for (var i in myElement.children) {
			if (myElement.children[i].id == "calDateText") {
				if (myElement.children[i].color == toggleColor) {
					myElement.children[i].color = "";
				} else {
					myElement.children[i].color = toggleColor;
            	}
         	}
      	}
   	}
}

/****************************************************************************/
/****************************************************************************/

function fSetSelectedDay(myElement){
	if (myElement.id == "calCell") {
		if (!isNaN(parseInt(myElement.children["calDateText"].innerText))) {
			myElement.bgColor = "#c0c0c0";
			objPrevElement.bgColor = "";
			document.all.calSelectedDate.value = parseInt(myElement.children["calDateText"].innerText);
			objPrevElement = myElement;
      	}
   	}
}

/****************************************************************************/
/****************************************************************************/

function fGetDaysInMonth(iMonth, iYear) {
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

/****************************************************************************/
/****************************************************************************/

function fBuildCal(iYear, iMonth, iDayStyle) {
	var aMonth = new Array();
	aMonth[0] = new Array(7);
	aMonth[1] = new Array(7);
	aMonth[2] = new Array(7);
	aMonth[3] = new Array(7);
	aMonth[4] = new Array(7);
	aMonth[5] = new Array(7);
	aMonth[6] = new Array(7);
	var dCalDate = new Date(iYear, iMonth-1, 1);
	var iDayOfFirst = dCalDate.getDay();
	var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
	var iVarDate = 1;
	var i, d, w;
	if (iDayStyle == 2) {
		aMonth[0][0] = "Domingo";
		aMonth[0][1] = "Lunes";
		aMonth[0][2] = "Martes";
		aMonth[0][3] = "Miércoles";
		aMonth[0][4] = "Jueves";
		aMonth[0][5] = "Viernes";
		aMonth[0][6] = "Sábado";
	} else if (iDayStyle == 1) {
		aMonth[0][0] = '<img src="disenioweb/imagenes/img/numeros_almanaque/d.jpg" alt="" width="19" height="16" />';
		aMonth[0][1] = '<img src="disenioweb/imagenes/img/numeros_almanaque/l.jpg" alt="" width="19" height="16" />';
		aMonth[0][2] = '<img src="disenioweb/imagenes/img/numeros_almanaque/m.jpg" alt="" width="19" height="16" />';
		aMonth[0][3] = '<img src="disenioweb/imagenes/img/numeros_almanaque/m.jpg" alt="" width="19" height="16" />';
		aMonth[0][4] = '<img src="disenioweb/imagenes/img/numeros_almanaque/j.jpg" alt="" width="19" height="16" />';
		aMonth[0][5] = '<img src="disenioweb/imagenes/img/numeros_almanaque/v.jpg" alt="" width="19" height="16" />';
		aMonth[0][6] = '<img src="disenioweb/imagenes/img/numeros_almanaque/s.jpg" alt="" width="19" height="16" />';
	} else {
		aMonth[0][0] = "Do";
		aMonth[0][1] = "Lu";
		aMonth[0][2] = "Ma";
		aMonth[0][3] = "Mi";
		aMonth[0][4] = "Ju";
		aMonth[0][5] = "Vi";
		aMonth[0][6] = "Sá";
	}
	for (d = iDayOfFirst; d < 7; d++) {
		aMonth[1][d] = iVarDate;
		iVarDate++;
	}
	for (w = 2; w < 7; w++) {
		for (d = 0; d < 7; d++) {
			if (iVarDate <= iDaysInMonth) {
				aMonth[w][d] = iVarDate;
				iVarDate++;
      		}
   		}
	}
	return aMonth;
}

/****************************************************************************/
/****************************************************************************/

function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) {
	var myMonth;
	var dFechaActual = new Date();
	var iDayOfMonth = dFechaActual.getDate();
	myMonth = fBuildCal(iYear, iMonth, iDayStyle);
	document.write("<table border='0'>")

	document.write("<tr>")
	document.write('<td colspan="8" scope="col"><img src="disenioweb/imagenes_dev/calendario/img_mes_' + iMonth + '.jpg" width="145" height="35"></td>')
	document.write('<td colspan="7" scope="col"><img src="disenioweb/imagenes_dev/calendario/img_grande_' + iDayOfMonth + '.jpg" width="50" height="35"></td>')
	document.write('</tr>')
	document.write("<table border='0'>")
	    
	document.write("<tr>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][0] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][1] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][2] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][3] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][4] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][5] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("<td >" + myMonth[0][6] + "</td>");
	document.write('<td rowspan="6" width="1"><img src="disenioweb/imagenes/img/numeros_almanaque/barras_violeta.jpg" alt="" width="1" height="120" /></td>');
	document.write("</tr>");
	
	for (w = 1; w < 7; w++) {
		document.write("<tr>")
		for (d = 0; d < 7; d++) {
			if (!isNaN(myMonth[w][d])) {
				document.write('<td>');
				document.write('<a href="javascript:;" target="_top" onclick="MM_nbGroup(' + "'" + 'down' + "'" + ',' + "'" + 'navbar1' + "'" + ',' + "'" + 'dia_' + myMonth[w][d] + "'" + ','+ "'" + 'disenioweb/imagenes_dev/calendario/img_dia_sobre_' + myMonth[w][d] + '.jpg' + "'" + ',1);" onMouseOver="MM_nbGroup('+ "'" +'over'+ "'" +','+ "'" +'dia_' + myMonth[w][d] +"'" +','+ "'" + 'disenioweb/imagenes_dev/calendario/img_dia_sobre_' + myMonth[w][d] + '.jpg'+ "'" +','+ "'" +'disenioweb/imagenes_dev/calendario/img_dia_sobre_' + myMonth[w][d] + '.jpg'+ "'" +',1);" onMouseOut="MM_nbGroup('+ "'" +'out'+ "'" +');">');
				document.write('<img src="disenioweb/imagenes/img/numeros_almanaque/htm_numeros/numeros_sueltos/dia_'+ myMonth[w][d] + '.jpg" alt="" width="15" height="14" border="0" id="dia_' + myMonth[w][d] + '" name="dia_' + myMonth[w][d] + '" onclick="" runat="server"/></a>');
				//document.write('<asp:Image ImageUrl="disenioweb/imagenes/img/numeros_almanaque/htm_numeros/numeros_sueltos/dia_'+ myMonth[w][d] + '.jpg" ID="dia_' + myMonth[w][d] + '" runat="server" /></a>');
				document.write("</td>")
			} else{
				document.write('<td></td>');
			}
		}
		document.write("</tr>");
	}
	document.write("</table>")
}

/****************************************************************************/
/****************************************************************************/

function fUpdateCal(iYear, iMonth) {
	myMonth = fBuildCal(iYear, iMonth);
	objPrevElement.bgColor = "";
	document.all.calSelectedDate.value = "";
	for (w = 1; w < 7; w++) {
		for (d = 0; d < 7; d++) {
			if (!isNaN(myMonth[w][d])) {
				calDateText[((7*w)+d)-7].innerText = myMonth[w][d];
			} else {
				calDateText[((7*w)+d)-7].innerText = " ";
         	}	
      	}
   	}
}

